//控制解除安置帮教管理列中按钮
function onJcbj(e) {
    //司法所显示申请解除帮教、司法局显示审批
    var record = e.value;
    if (record != null) {
        var arr = record.split("@");
        var SPZT = arr[0];//审批状态
        var level = arr[1];//用户level
    }
    var s = "";
    <!-- spzt '审批状态1未申请 2已申请 3审批通过 4审批失败' -->
    <!-- 司法所 -->
    if (level == '03') {
        if(SPZT == '-1' || SPZT == '1'){
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="applyReleaseHelpEduWindow()"  >&nbsp;&nbsp;申请解除帮教&nbsp;&nbsp;</a>&nbsp';
        } else if(SPZT == '4'){
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="applyReleaseHelpEduWindowAgain(id)">&nbsp;&nbsp;重新申请&nbsp;&nbsp;</a>&nbsp';
            s += '&nbsp;<a class="mini-button mini-button-success" onclick="auditResult()">&nbsp;&nbsp;查看审核结果&nbsp;&nbsp;</a>';
        } else if(SPZT == '3'){
            s += '&nbsp;<a class="mini-button mini-button-success" onclick="auditResult()">&nbsp;&nbsp;查看审核结果&nbsp;&nbsp;</a>';
        }
    } else if (level == '08') {
        <!-- 区县司法局 -->
        if (SPZT == '2') {
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="auditingWindow()"  >&nbsp;&nbsp;审批&nbsp;&nbsp;</a>&nbsp';
        } else if (SPZT == '3' || SPZT == '4') {
            s += '&nbsp;<a class="mini-button mini-button-success" onclick="auditResult()">&nbsp;&nbsp;查看审核结果&nbsp;&nbsp;</a>&nbsp';
        }
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="toViewHjqc()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//申请解除跳转页面
function applyReleaseHelpEduWindow() {
    var row = grid.getSelected();
    if (row) {
        var jieChuAutoDate = row.jieChuAutoDate;
        var spzt = row.spzt;
        //审批通过、失败
        if (spzt == 3 || spzt == 4) {
            commonEdit("/azbj/jcbjgl/auditingReleaseHelpEdu/check", "解除帮教查看", row, "42%", "42%", true, false, true, callback);
        } else if (spzt == 2) {
            //审批中
            commonEdit("/azbj/jcbjgl/applyReleaseHelpEdu/check", "解除帮教查看", row, "32%", "42%", true, false, true, callback);
        } else {
            //未申请
            commonEdit("/azbj/jcbjgl/applyReleaseHelpEdu/edit?jieChuAutoDate=" + jieChuAutoDate, "解除帮教申请", row, "32%", "50%", true, true, true, callback);
            function callback() {
                grid.reload();
            }
        }
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//审批跳转页面
function auditingWindow() {
    var row = grid.getSelected();
    var jieChuAutoDate = row.jieChuAutoDate;
    if (row) {
        var spzt = row.spzt;
        if (spzt == 3 || spzt == 4) {//审批通过、失败
            commonEdit("/azbj/jcbjgl/auditingReleaseHelpEdu/check", "解除帮教查看", row, "32%", "42%", true, false, true, callback);
        } else {
            //审批中
            commonEdit("/azbj/jcbjgl/auditingReleaseHelpEdu/edit?jieChuAutoDate=" +jieChuAutoDate , "解除帮教审批", row, "32%", "52%", true, false, true, callback);
            function callback() {
                grid.reload();
            }
        }
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//审批状态code转换
function onCheckStatusCode(e) {
    var checkStatus = e.value;
    if (checkStatus == 1 || checkStatus == "" || checkStatus == null) {
        return "未申请";
    } else if (checkStatus == 2) {
        return "审批中";
    } else if (checkStatus == 3) {
        return "审批通过";
    } else if (checkStatus == 4) {
        return "审批失败";
    }
}

//解除原因code转换
function onReleaseReasonStatus(e) {
    var releaseReasonStatus = e.value;
    if (releaseReasonStatus == 1) {
        return "期满解除";
    } else if (releaseReasonStatus == 2) {
        return "死亡";
    } else if (releaseReasonStatus == 3) {
        return "重新犯罪";
    } else {
        return "无";
    }
}

//转换为年月日
function onYearMonthDayDateRenderer(e) {
    if (e.value) {
        var date = new Date(e.value);
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
        var formatTime = Y + M + D;
        return formatTime;
    } else {
        return "";
    }
}

/**
 * 解除帮教 处理解除帮教日期
 * @param e
 * @returns {*}
 */
function transferDate(e) {
    var val = e.value;
    if(val==undefined) {
        val = '-';
    }else if (val.indexOf('剩余-') > -1) {
        var str = val.split('-');
        str[0] = '超过';
        val = str[0]+str[1];
    }
    return val;
}

//性别code转换
function onGetGenderName(e) {
    var gender = e.value;
    if (gender == 1) {
        return "男性";
    } else if (gender == 2) {
        return "女性";
    } else if (gender == 9) {
        return "未说明的性别";
    } else if (gender == 0) {
        return "未知的性别";
    }
}

//查看
function toViewHjqc() {
    var row = grid.getSelected();
    mini.open({
        url: "/azbj/bjdxInfo/hjqc/toViewTabs/view?priNum=" + row.priNum,
        title: "查看",
        width: "60%",
        height: "80%",
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

function applyReleaseHelpEduWindowAgain() {
    var row = grid.getSelected();
    var jieChuAutoDate = row.jieChuAutoDate;
    var releaseDate1 = row.releaseDate1;
    //重新发起申请需要选中的id
    var id = row.id;
    //重新申请"
    commonEdit("/azbj/jcbjgl/applyReleaseHelpEdu/editAgain?jieChuAutoDate=" + jieChuAutoDate + "&releaseDate1=" + releaseDate1 + "&id=" + id, "重新申请", row, "32%", "55%", true, false, true, callback);
    function callback() {
        grid.reload();
    }
}

function auditResult() {
    //查看审核结果
    var row = grid.getSelected();
    var jieChuAutoDate = row.jieChuAutoDate;
    var releaseDate1 = row.releaseDate1;
    commonEdit("/azbj/bjdxInfo/hjqc/toViewTabs/view/auditResult?priNum=" + row.priNum + "&jieChuAutoDate=" + jieChuAutoDate + "&releaseDate1=" + releaseDate1, "查看审核结果", row, "32%", "42%", true, false, true, callback);

    function callback() {
        grid.reload();
    }
}